﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace QUANLYNHASACH
{
    public partial class QuanlyGroup : Form
    {
        QUANLYNHASACH.App_code.BLL.Group_BLL bllGroup = new QUANLYNHASACH.App_code.BLL.Group_BLL();
        public QuanlyGroup()
        {
            InitializeComponent();
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            string idGroup = txtIdGroup.Text;
            string Capbac = txtCapBac.Text;
            bllGroup.ThemGroup(idGroup, Capbac);
            GridGroup.DataSource = bllGroup.LayDanhSachGroup();
        }

        private void btnSua_Click(object sender, EventArgs e)
        {
             bool isCheck = false;
            for (int i = 0; i < this.GridGroup.Rows.Count; i++)
            {
                if (this.GridGroup.Rows[i].Cells[0].Value != null)
                {
                    isCheck = (bool)this.GridGroup.Rows[i].Cells[0].Value;
                    string idGroup = this.GridGroup.Rows[i].Cells[1].Value.ToString();
                    string Capbac = this.GridGroup.Rows[i].Cells[2].Value.ToString();
                    
                   
                    if (isCheck == true)
                    {
                        bllGroup.CapNhatGroup(idGroup, Capbac);
                    }
                }
            }
            MessageBox.Show("Đã cập nhật danh sách group thành công", "Thông báo");
        
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            bool isCheck = false;
            for (int i = 0; i < this.GridGroup.Rows.Count; i++)
            {
                if (this.GridGroup.Rows[i].Cells[0].Value != null)
                {
                    isCheck = (bool)this.GridGroup.Rows[i].Cells[0].Value;
                    string idGroup = this.GridGroup.Rows[i].Cells[1].Value.ToString();

                    if (isCheck == true)
                    {
                        bllGroup.XoaGroup(idGroup);

                    }
                    GridGroup.DataSource = bllGroup.LayDanhSachGroup();
                }
            }
        }

        private void QuanlyGroup_Load(object sender, EventArgs e)
        {
            GridGroup.DataSource = bllGroup.LayDanhSachGroup();
        }

    }
}
